import { ro } from 'element-plus/es/locale/index.mjs';
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: "/index"
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/JSB/Login.vue')
    },
    {
      path: '/Register',
      name: 'Register',
      component: () => import('../views/JSB/Register.vue')
    },
    {
      path: '/Account',
      name: 'Account',
      component: () => import('../views/JSB/Account.vue')
    },

    {
      path: '/index',
      name: 'index',
      component: () => import('../views/Text.vue'),
      children: [
        {
          path: '/index/deal',
          name: 'deal',
          component: () => import('../views/SZH/monitoring/JianDeal.vue')
        },
        {
          path: '/index/shop',
          name: 'shop',
          component: () => import('../views/SZH/monitoring/JianShop.vue')
        },
        {
          path: '/index/user',
          name: 'user',
          component: () => import('../views/SZH/monitoring/JianUser.vue')
        },
        {
          path: '/index/yun',
          name: 'yun',
          component: () => import('../views/SZH/monitoring/JianYun.vue')
        }, {
          path: '/index/aftersale',
          name: 'aftersale',
          component: () => import('../views/SZH/order/AfterSale.vue')
        },
        {
          path: '/index/delivergoods',
          name: 'delivergoods',
          component: () => import('../views/SZH/order/DeliverGoods.vue')
        },
        {
          path:'/index/orderform',
          name:'orderform',
          component: () => import('../views/SZH/order/OrderForm.vue')
        },
        {
          path:'/index/shoplist',
          name:'shoplist',
          component: () => import('../views/SZH/shop/ShopList.vue')
        },
        {
          path:'/index/shopinventory',
          name:'shopinventory',
          component: () => import('../views/SZH/shop/ShopInventory.vue')
        },
        {
          path:'/index/shopcate',
          name:'shopcate',
          component: () => import('../views/SZH/shop/ShopCate.vue')
        },
        {
          path:'/index/addshop',
          name:'addshop',
          component: () => import('../views/JSB/addshop.vue')
        },
        {
          path:'/index/System',
          name:'System',
          component: () => import('../views/JSB/System.vue')
        },
        {
          path:'/index/System1',
          name:'System1',
          component: () => import('../views/JSB/System1.vue')
        },
        {
          path:'/index/management',
          name:'management',
          component: () => import('../views/ZJM/Admin/Management.vue')
        },
        {
          path:'/index/look',
          name:'look',
          component: () => import('../views/ZJM/Admin/Look.vue')
        },
        {
          path:'/index/label',
          name:'label',
          component: () => import('../views/ZJM/Admin/Label.vue')
        },
        {
          path:'/index/advertising',
          name:'advertising',
          component: () => import('../views/ZJM/Content/Advertising.vue')
        },
        {
          path:'/index/platform',
          name:'platform',
          component: () => import('../views/ZJM/Content/Platform.vue')
        },
        {
          path:'/index/search',
          name:'search',
          component: () => import('../views/ZJM/Content/Search.vue')
        },
        {
          path:'/index/specialmanagement',
          name:'specialmanagement',
          component: () => import('../views/ZJM/Content/SpecialManagement.vue'),
        },
        {
          path:'/index/addSman',
          name:'addSman',
          component: () => import('../views/ZJM/Content/AddSman.vue')
        },
        {
          path:'/index/editSman',
          name:'editSman',
          component: () => import('../views/ZJM/Content/EditSman.vue')
        },
        {
          path:'/index/discounts',
          name:'discounts',
          component: () => import('../views/ZJM/Operation/Discounts.vue')
        },
        {
          path:'/index/group',
          name:'group',
          component: () => import('../views/ZJM/Operation/Group Booking.vue')
        },
        {
          path:'/index/seckill',
          name:'seckill',
          component: () => import('../views/ZJM/Operation/Seckill.vue')
        },
        {
          path:'/index/special',
          name:'special',
          component: () => import('../views/ZJM/Operation/Special.vue')
        },
        {
          path:'/index/addlist',
          name:'addlist',
          component: () => import('../views/JSB/addlist.vue')
        },
      ]
    },

  ]
})
// 全局守卫：登录拦截 本地没有存token,请重新登录
router.beforeEach((to, from, next) => {
	//判断有没有登录
		if (to.name == "login" || to.name == "Register" || to.name == "Account") {
			next();
		} else{
			if (localStorage.getItem("token")) {
				next();
			} else {
				next({ name: "login" });
    }
  }
});

export default router
